package cjyyp.netty中futrue和promise接口;

import io.netty.channel.EventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.util.concurrent.DefaultPromise;
import lombok.extern.slf4j.Slf4j;

import java.nio.channels.SocketChannel;
import java.util.concurrent.ExecutionException;

@Slf4j
public class 使用netty中的promise {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        EventLoop eventLoop = new NioEventLoopGroup(2).next();
        DefaultPromise<Integer> promise = new DefaultPromise<>(eventLoop);
        new Thread(()->{
            try {
                Thread.sleep(1000);
                System.out.println(10/0);
            } catch (Exception e) {
                promise.setFailure(e);
            }
            log.info("执行中。。。");
            promise.setSuccess(20);
        },"thread-1").start();
        log.info("结果是[{}]",promise.get());
    }
}
